package com.bz.xtcx.manager.task;

import com.bz.xtcx.manager.entity.CmsMeeting;
import com.bz.xtcx.manager.entity.User;
import com.bz.xtcx.manager.mapper.CmsMeetingMapper;
import com.bz.xtcx.manager.persist.conditions.MeetingCondition;
import com.bz.xtcx.manager.utils.WzStrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CmsMeetingRefService {

    /** 日志. */
    private final Logger logger = LoggerFactory.getLogger(CmsMeetingRefService.class);

    @Autowired
    private CmsMeetingMapper cmsMeetingMapper;

    /**
     * 发起申请短信通知处理.
     */
    @JmsListener(destination = "jmrh_ref_user_meeting_queue")
    public void reqMeetingMobileNotice(User data) {
        logger.info("用户[" + data.getEmail() + "]关联对接申请开始");
        if (null == data || WzStrUtil.isBlank(data.getUserId()) ||  WzStrUtil.isBlank(data.getCode())) {
            logger.error("用户[" + data.getEmail() + "]信息不完整");
            return;
        }
        MeetingCondition mcVo = new MeetingCondition();
        mcVo.setFromer(data.getUserId());
        mcVo.setTargeterCN(data.getCode());
        mcVo.setIsFormOrToMe(2);
        List<CmsMeeting> cmLs = cmsMeetingMapper.selectForUser(mcVo);
        if (null != cmLs && 0 < cmLs.size()) {
            CmsMeeting updVo = null;
            for (CmsMeeting cmData : cmLs) {
                updVo = new CmsMeeting();
                updVo.setTargeter(data.getUserId());
                updVo.setId(cmData.getId());
                try {
                    cmsMeetingMapper.updateByPrimaryKeySelective(updVo);
                } catch (Exception e) {
                    logger.error("对接申请[" + cmData.getId() + "]关联失败", e);
                }
            }
        }
        logger.info("用户[" + data.getEmail() + "]关联对接申请结束");
    }
}
